@@ -59,6 +59,10 @@ class Agent < ActiveRecord::Base |
||
| 59 | 59 |
where(:type => type) |
| 60 | 60 |
} |
| 61 | 61 |
|
| 62 |
+ def credential(name) |
|
| 63 |
+ user.user_credentials.where(:credential_name => name).limit(1).first.credential_value rescue nil |
|
| 64 |
+ end |
|
| 65 |
+ |
|
| 62 | 66 |
def check |
| 63 | 67 |
# Implement me in your subclass of Agent. |
| 64 | 68 |
end |
@@ -1,4 +1,3 @@ |
||
| 1 |
-hello doctor |
|
| 2 | 1 |
<div class='container'> |
| 3 | 2 |
<div class='row'> |
| 4 | 3 |
<div class='span8 offset2'> |
@@ -49,7 +48,6 @@ hello doctor |
||
| 49 | 48 |
<div class='form-actions'> |
| 50 | 49 |
<%= f.submit "Update", :class => "btn btn-primary" %> |
| 51 | 50 |
</div> |
| 52 |
- now the new stuff |
|
| 53 | 51 |
<div class="control-group"> |
| 54 | 52 |
<%= f.fields_for(:user_credentials) do |uc| %> |
| 55 | 53 |
<%= render 'user_credential_fields', :f => uc %> |
@@ -0,0 +1,8 @@ |
||
| 1 |
+bob_aws_key: |
|
| 2 |
+ user: bob |
|
| 3 |
+ credential_name: aws_key |
|
| 4 |
+ credential_value: 2222222222 |
|
| 5 |
+bob_aws_secret: |
|
| 6 |
+ user: bob |
|
| 7 |
+ credential_name: aws_secret |
|
| 8 |
+ credential_value: 1111111111 |
@@ -27,6 +27,16 @@ describe Agent do |
||
| 27 | 27 |
end |
| 28 | 28 |
end |
| 29 | 29 |
|
| 30 |
+ describe "credential" do |
|
| 31 |
+ it "should return the value of the credential when credential is present" do |
|
| 32 |
+ agents(:bob_weather_agent).credential("aws_secret").should == user_credentials(:bob_aws_secret).credential_value
|
|
| 33 |
+ end |
|
| 34 |
+ |
|
| 35 |
+ it "should return nil when credential is not present" do |
|
| 36 |
+ agents(:bob_weather_agent).credential("non_existing_credential").should == nil
|
|
| 37 |
+ end |
|
| 38 |
+ end |
|
| 39 |
+ |
|
| 30 | 40 |
describe "changes to type" do |
| 31 | 41 |
it "validates types" do |
| 32 | 42 |
source = Agent.new |
@@ -473,4 +483,4 @@ describe Agent do |
||
| 473 | 483 |
end |
| 474 | 484 |
end |
| 475 | 485 |
end |
| 476 |
-end |
|
| 486 |
+end |